﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;

namespace Module.FlowChart.Model
{
    internal abstract class WorkPage
    {

        static public Dictionary<string, Func<BinaryReader, WorkPage>> WorkPageLoaders = new Dictionary<string, Func<BinaryReader, WorkPage>>();
        static public Dictionary<string, Func<string, WorkPage>> WorkPageCreators = new Dictionary<string, Func<string, WorkPage>>();
        static public Dictionary<string, Func<int, string>> WorkPageNameCreator = new Dictionary<string, Func<int, string>>();
        static public string DefaultPageType;

        public Size PaperSize = new Size(19200, 10800);

        protected string m_name;
        public Document Owner;
        Action OnChange;


        public bool IsChanged { get; set; }
        public string Name
        {
            get => m_name;
            set
            {
                string org = m_name;
                m_name = value;
                _OnChangeName(org, value);
            }
        }
        public abstract string TypeName { get; }
        public int StartNode { get; internal set; }

        public WorkPage()
        {
            OnChange = null;
            IsChanged = false;
        }
        public WorkPage(string name)
        {
            m_name = name;
            OnChange = null;
            IsChanged = false;
        }

        /// <summary>
        /// 当重命名时触发 可用m_name=from来取消修改
        /// </summary>
        protected abstract void _OnChangeName(string from, string to);
        /// <summary>
        /// 保存当前工作簿
        /// </summary>
        /// <param name="bw"></param>
        /// <returns></returns>
        public abstract bool Save(BinaryWriter bw);
        public abstract WorkPage LoadFromBytes(BinaryReader br);
    }

}

